import '@babel/polyfill'
import Vue from 'vue'
import './plugins/vuetify'
import App from './App.vue'
import router from './router'
import './registerServiceWorker'
import { createProvider } from './vue-apollo'

// import MutationStatus from './graphql/Mutation/Status.graphql'

Vue.config.productionTip = false

console.log(process.env)

Vue.filter('withCDN', uri => {
  return `${process.env.VUE_APP_CDN}/products/${uri}`
})

const apolloProvider = createProvider()

router.beforeEach((to, from, next) => {
  console.log('beforeEach', to, from)
  // 临时解决将 js 放置到 CDN 后路由链接带上域名刷新的问题
  const s = to.path.split('/')
  if (s.length > 1 && s[1].startsWith('https')) {
    let uri = ''
    for (let i = 3; i < s.length; i++) {
      uri += '/' + s[i]
    }
    next(uri)
    return
  }
  next()
})

/* router.afterEach((to, from) => {
  console.log('afterEach', to, from)
  apolloProvider.defaultClient.mutate({
    mutation: MutationStatus,
    variables: {
      isLoading: false
    }
  })
}) */

new Vue({
  router,
  apolloProvider,
  render: h => h(App)
}).$mount('#app')
